package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.entity.Detail;
import com.woniu.mapper.DetailMapper;
import com.woniu.service.DetailService;
import com.woniu.uitls.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DetailServiceImpl implements DetailService {
    @Resource
    private DetailMapper detailMapper;

    @Override
    public ResponseUtil findAll(Integer pageNum, Integer pageSize,Integer sortId) {
        PageHelper.startPage(pageNum,pageSize);
        if (sortId == 0){
            sortId = null;
        }
        List<Detail> all = detailMapper.findAll(sortId);
        PageInfo pageInfo = new PageInfo(all);

        return ResponseUtil.get(200,"查询成功",pageInfo);
    }

    @Override
    public ResponseUtil findById(Integer dId) {
        Detail byId = detailMapper.findById(dId);
        return ResponseUtil.get(200,"查询成功",byId);
    }

    @Override
    public ResponseUtil add(Detail detail) {
        Integer i = detailMapper.add(detail);
        return ResponseUtil.get(200,"添加成功");
    }

    @Override
    public ResponseUtil update(Detail detail) {
        Integer update = detailMapper.update(detail);
        return ResponseUtil.get(200,"更新成功",update);
    }

    @Override
    public ResponseUtil delete(Integer dId) {
        Integer delete = detailMapper.delete(dId);
        return ResponseUtil.get(200,"删除成功",delete);
    }
}
